package com.liu.stockmarket

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.fragment.app.Fragment
import com.liu.stockmarket.databinding.RvEmptyViewBinding

abstract class BaseFragment : Fragment() {
    lateinit var emptyViewBinding: RvEmptyViewBinding
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        emptyViewBinding = RvEmptyViewBinding.inflate(inflater,container,false)
        val root = initView(inflater, container, savedInstanceState)

        observer()
        listener()

        emptyViewBinding.root.setOnClickListener {
            emptyViewOnListener()
        }
        return root

    }
    open fun emptyViewOnListener() {
        Log.w(this.javaClass.name, "空视图点击事件未设置")
    }

    // 无效
    fun addEmpty(parentView:ViewGroup) {
        val view = emptyViewBinding.root
        val layoutParams = parentView.layoutParams
        layoutParams.height = MATCH_PARENT
        layoutParams.width = MATCH_PARENT
        parentView.layoutParams = layoutParams
        parentView.addView(view,LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT))
    }

    abstract fun initView(inflater: LayoutInflater,
                          container: ViewGroup?,
                          savedInstanceState: Bundle?): View

    /**
     * 事件
     */
    abstract fun listener()

    /**
     * 订阅
     */
    abstract fun observer()
}